package com.fick.tags;

import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fick.hibernate.dao.LinkClassDAO;
import com.fick.hibernate.model.LinkClass;

/**
 * 显示指定id的链接分类名称
 * @author 王浩强
 * 2009-08-14
 * 
 * **/
public class LinkClassNameTag extends TagSupport {
	private static Log log = LogFactory.getLog(NewsTag.class);
	//分类id
	private int classid=0;
	//是否带连接
	private boolean isLink=false;
	//<a>标签的属性
	private String linkAttr="";
	//<a>标签href要连接的页面
	private String linkPage="";
	
	public int doStartTag() throws JspException {
			
		try {
			StringBuffer sb = new StringBuffer();
			LinkClassDAO dao=new LinkClassDAO();
			LinkClass linkClass=dao.findById(classid);
			if (linkClass!=null) {
				if (isLink) {
					sb.append("<a href='");
					sb.append(linkPage);
					sb.append("?classid=");
					sb.append(classid);
					sb.append("' ");
					sb.append(linkAttr);
					sb.append(" >");
					sb.append(linkClass.getClassName());
					sb.append("</a>");
				}else {
					sb.append(linkClass.getClassName());
				}
			}
			JspWriter out = pageContext.getOut();
			out.println(sb.toString());
			out.flush();
		}catch(IOException e)
		{
			log.error("标签显示错误"+e);
			e.printStackTrace();
		}
		return SKIP_BODY;
	}

	public int getClassid() {
		return classid;
	}

	public void setClassid(int classid) {
		this.classid = classid;
	}

	public boolean getIsLink() {
		return isLink;
	}

	public void setIsLink(boolean isLink) {
		this.isLink = isLink;
	}

	public String getLinkAttr() {
		return linkAttr;
	}

	public void setLinkAttr(String linkAttr) {
		this.linkAttr = linkAttr;
	}

	public String getLinkPage() {
		return linkPage;
	}

	public void setLinkPage(String linkPage) {
		this.linkPage = linkPage;
	}
	
}
